#coding:utf-8
'''
Created on 2019年2月18日

@author: wps
'''
import requests
import json

from flask import request, redirect,jsonify
from flask_restful import Resource,reqparse

from app.utils.decorator import add_api_resource

@add_api_resource('/test')
class Test(Resource):
    """test
    """
    def get(self):
        return ('success')
    
@add_api_resource('/v1/api/weather/info')
class GetWeatherInfo(Resource):
    """获取天气信息
    """
    def post(self):
        return self.handle()
    
    def get(self):
        return self.handle()
    
    def handle(self):
        url = 'http://t.weather.sojson.com/api/weather/city/101100207'
        result = requests.get(url)
        jsd = json.loads(result.text)
        weather_json = jsd.get('data')
        data = {'error':0,'error_msg':'success','data': weather_json}
        return jsonify(data)